﻿Public Class Email


    ''' <summary>
    ''' As configurações de smtp devem estar no web.config do projeto
    ''' EnableSsl = True
    ''' </summary>
    ''' <param name="Para"></param>
    ''' <param name="Titulo"></param>
    ''' <param name="Texto"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function EnviarEmail(ByVal Para As String, ByVal Titulo As String, ByVal Texto As String) As Boolean
        EnviarEmail(Para, Titulo, Texto, True)
    End Function

    ''' <summary>
    ''' As configurações de smtp devem estar no web.config do projeto
    ''' </summary>
    ''' <param name="Para"></param>
    ''' <param name="Titulo"></param>
    ''' <param name="Texto"></param>
    ''' <param name="EnableSsl"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function EnviarEmail(ByVal Para As String, ByVal Titulo As String, ByVal Texto As String, ByVal EnableSsl As Boolean) As Boolean
        Try
            Dim smtpCli As New System.Net.Mail.SmtpClient
            Dim m As New System.Net.Mail.MailMessage
            m.To.Add(Para)
            m.Body = Texto
            m.BodyEncoding = System.Text.Encoding.UTF8
            m.Subject = Titulo
            m.IsBodyHtml = True
            smtpCli.EnableSsl = EnableSsl
            smtpCli.Send(m)
            Return True
        Catch ex As Exception
            Web.Javascript.Alert(ex.Message.ToString)
            Return False
        End Try
    End Function

    ''' <summary>
    ''' As configurações de smtp devem estar no web.config do projeto
    ''' </summary>
    ''' <param name="Para">Lista de emails</param>
    ''' <param name="Titulo"></param>
    ''' <param name="Texto"></param>
    ''' <param name="EnableSsl"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function EnviarEmail(ByVal Para As List(Of String), ByVal Titulo As String, ByVal Texto As String, ByVal EnableSsl As Boolean) As Boolean
        Try
            Dim smtpCli As New System.Net.Mail.SmtpClient
            Dim m As New System.Net.Mail.MailMessage
            For Each item As String In Para
                m.To.Add(item)
            Next
            m.Body = Texto
            m.BodyEncoding = System.Text.Encoding.UTF8
            m.Subject = Titulo
            m.IsBodyHtml = True
            smtpCli.EnableSsl = EnableSsl
            smtpCli.Send(m)
            Return True
        Catch ex As Exception
            Web.Javascript.Alert(ex.Message.ToString)
            Return False
        End Try
    End Function


End Class
